<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:insert="common/person-pc/header::personHeadBar('我的信息','/static/Kz.layedit/Content/Layui-KnifeZ/css/layui.css')">
<body class="centre" style="">
<!-- 头部 -->
<!-- 头部信息 -->
<div th:insert="common/person-pc/top::personTopBar(${resCategoryModel})"/>

<div class="ey-body-bg">
    <div class="ey-body">
        <div class="ey-container w1200">
            <div th:insert="common/person-pc/right::rightBar(${show})"/>
            <!-- 中部 -->
            <div class="ey-con fr">
                <div class="el-main main-bg">
                    <div class="column-title mb20">
                        <div class="column-name">发消息</div>
                    </div>
                    <div class="user-info">
                        <div class="info fr">
                            <form name="theForm" id="theForm" class="layui-form">
                                <div class="layui-form-item">
                                    <label class="layui-form-label required">收信人：</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="receiveUserName" lay-verify="required" id="receiveUserNameId" th:value="${receiveUserName}" autocomplete="off" placeholder="请输入收信人" class="layui-input" >
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label required">标 题：</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="sendTitle" lay-verify="required" id="sendTitleId" autocomplete="off" placeholder="请输入标题" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label required">内 容：</label>
                                    <div class="layui-input-block">
                                        <textarea id="sendContentId" lay-verify="sendContent" name="sendContent" required autocomplete="off" placeholder="请输入内容"></textarea>
                                    </div>
                                </div>
                                <!-- 结束 -->
                                <div class="item-from-row">
                                    <div class="from-row-l">
                                        &nbsp;
                                    </div>
                                    <div class="from-row-r">
                                        <button class="layui-btn layui-btn-danger" lay-submit="" lay-filter="formSubmit">发送消息</button>
                                    </div>
                                </div>
                            </form>

                        </div>
                    </div>

                </div>
            </div>
            <!-- 中部结束 -->
        </div>
    </div>
</div>

<!-- 底部 -->
<div class="ey-footer">
    <footer class="container">
        <p>Copyright © 2012-2018 资源基地 版权所有</p>
    </footer>
</div>

<script type="text/javascript" th:src="@{'/static/Kz.layedit/Content/Layui-KnifeZ/layui.js'}"></script>

<script>
    layui.use(['form', 'layedit', 'layer'], function () {
        var form = layui.form,
            layedit = layui.layedit,
            layer = layui.layer;
        //创建一个编辑器
        var index = layedit.build('sendContentId', {
            tool: [
                'strong' //加粗
                ,'italic' //斜体
                ,'underline' //下划线
                ,'del' //删除线
                ,'|' //分割线
                ,'left' //左对齐
                ,'center' //居中对齐
                ,'right' //右对齐
                ,'link' //超链接
                ,'unlink' //清除链接
            ],
            height: 100
        });

        //提交时把值同步到文本域中
        form.verify({
            sendContent: function (value) {
                return layedit.sync(index);
            }
        });

        form.on("submit(formSubmit)", function (data) {
            console.log(data)
            if (data.field == null || data.field == "") {
                layer.msg("请编写相应内容数据", {icon: 2})
            } else {
                var receiveUserName = data.field.receiveUserName;
                var sendContent = data.field.sendContent;
                var sendTitle = data.field.sendTitle;
                if (sendTitle == null || sendTitle == "") {
                    layer.msg("请输入标题", {icon: 2});
                    return false;
                }
                if (sendContent == null || sendContent == "") {
                    layer.msg("请输入内容", {icon: 2});
                    return false;
                }
                if (receiveUserName == null || receiveUserName == "") {
                    layer.msg("请输入收信人", {icon: 2});
                    return false;
                }
                $.ajax({
                    data: {
                        "content": sendContent,
                        "receiveName": receiveUserName,
                        "title": sendTitle
                    },
                    url: "/user/sendMessageToReceiveId",
                    type: "POST",
                    success: function (res) {
                        layer.closeAll();
                        if (res.rt == 1) {
                            layer.msg("发送成功！", {icon: 1});
                            window.location.reload();
                        }else if (res.rt == -1) {
                            showErrorMsg("未登录请先登录!");
                        }else if (res.rt == -2) {
                            showErrorMsg("收信人不存在!");
                        } else {
                            showErrorAlert("发送失败！");
                        }
                    },
                    error: function (e) {
                        layer.closeAll();
                        showErrorAlert("网络异常,请稍后再试!");
                    }
                });
            }
            return false;
        });
    });
</script>

</body>
</html>
